var clientApp = angular.module('clientApp');

clientApp.filter('imgPath', ['Constant', 'StringUtil', function(Constant, StringUtil) {
    return function(url, external) {
        if (StringUtil.isEmpty(url)) {
            return undefined;
        }
        if (StringUtil.isEmpty(external))  external = true;
        if (url.indexOf('/files') >= 0)  {
            external = true;
        } else {
            external = false;
        }

        if (external) {
            url = Constant.UploadUrl + url;
        }
        return url;
    }
}]);

clientApp.filter('thumbPath', ['Constant', 'StringUtil', function(Constant, StringUtil) {
    return function(url) {
        if (StringUtil.isEmpty(url)) {
            return undefined;
        }
        var inx = url.lastIndexOf('/');
        var rst = url.substring(0, inx + 1) + 'thumbnail' + url.substring(inx);
        return rst;
    }
}]);

clientApp.filter('iconClass', ['$rootScope', 'Constant', 'StringUtil', function($rootScope, Constant, StringUtil) {
    return function(sub) {
        var rst = sub.code;
        if ($rootScope.CurrentSub.id == sub.id) {
            rst += '-h';
        }

        return rst;
    }
}]);